package me.jiatao.usercenter.mvp.presenter

import me.jiatao.baselibrary.mvp.presenter.BasePresenter
import me.jiatao.baselibrary.rx.BaseSubscriber
import me.jiatao.baselibrary.rx.execute
import me.jiatao.usercenter.mvp.view.RegisterView
import me.jiatao.usercenter.mvp.service.impl.UserServiceImpl
import javax.inject.Inject

class RegisterPresenter @Inject constructor() : BasePresenter<RegisterView>() {

    @Inject
    lateinit var userService: UserServiceImpl

    fun register(mobile: String, pwd: String, verifyCode: String) {

        if (!checkNetWork()) {
            return
        }

        mView.showLoading()

        userService
            .register(mobile, pwd, verifyCode)
            .execute(object : BaseSubscriber<Boolean>(mView) {
                override fun onNext(data: Boolean) {
                    if (data) {
                        mView.onRegisterResult("注册成功")

                        mView.hideLoading()
                    }
                }
            }, mLifecycleProvider)
    }
}